package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.enums.ConfessionalWallOrderType;
import com.codedancer.campus.po.ConfessionalWall;
import com.codedancer.campus.qo.confessionalWall.ConfessionalWallSearchQo;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface ConfessionalWallMapper extends BaseMapper<ConfessionalWall> {

    /**
     * 分页查询表白墙(客户端)
     *
     * @param confessionalWallPage
     * @param confessionalWallSearchQo
     * @return
     */
    default IPage<ConfessionalWall> pageToClient(Page<ConfessionalWall> confessionalWallPage,
        ConfessionalWallSearchQo confessionalWallSearchQo) {
        LambdaQueryWrapper<ConfessionalWall> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 若是默认排序和时间降序排序
        if (confessionalWallSearchQo.getOrderType()
            .equals(ConfessionalWallOrderType.DEFAULT.getValue()) ||
            confessionalWallSearchQo.getOrderType()
                .equals(ConfessionalWallOrderType.TIME_DESC.getValue())) {
            lambdaQueryWrapper.orderByDesc(ConfessionalWall::getCreateTime);
        }
        // 时间升序
        if (confessionalWallSearchQo.getOrderType()
            .equals(ConfessionalWallOrderType.TIME_ASC.getValue())) {
            lambdaQueryWrapper.orderByAsc(ConfessionalWall::getCreateTime);
        }
        // 只能查询到本学校
        lambdaQueryWrapper.eq(ConfessionalWall::getPublishSchoolUuid,confessionalWallSearchQo.getPublishSchoolUuid());
        return selectPage(confessionalWallPage, lambdaQueryWrapper);
    }

    /**
     * 分页查询表白墙(管理端)
     *
     * @param confessionalWallPage
     * @param confessionalWallSearchQo
     * @return
     */
    IPage<ConfessionalWall> pageToManager(Page<ConfessionalWall> confessionalWallPage,
        @Param("confessionalWallSearchQo") ConfessionalWallSearchQo confessionalWallSearchQo);

    /**
     * 查询出需要导出的表白墙数据
     * @param confessionalWallSearchQo
     * @return
     */
    List<ConfessionalWall> listExportConfessionalWall(@Param("confessionalWallSearchQo") ConfessionalWallSearchQo confessionalWallSearchQo);

    /**
     * 分页用户查询表白墙
     * @param confessionalWallPage
     * @param confessionalWallSearchQo
     * @return
     */
    default IPage<ConfessionalWall> page2User(Page<ConfessionalWall> confessionalWallPage, ConfessionalWallSearchQo confessionalWallSearchQo){
        LambdaQueryWrapper<ConfessionalWall> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 若是默认排序和时间降序排序
        if (confessionalWallSearchQo.getOrderType()
            .equals(ConfessionalWallOrderType.DEFAULT.getValue()) ||
            confessionalWallSearchQo.getOrderType()
                .equals(ConfessionalWallOrderType.TIME_DESC.getValue())) {
            lambdaQueryWrapper.orderByDesc(ConfessionalWall::getCreateTime);
        }
        // 时间升序
        if (confessionalWallSearchQo.getOrderType()
            .equals(ConfessionalWallOrderType.TIME_ASC.getValue())) {
            lambdaQueryWrapper.orderByAsc(ConfessionalWall::getCreateTime);
        }
        lambdaQueryWrapper.eq(ConfessionalWall::getPublishUserUuid,confessionalWallSearchQo.getCurrentUserUuid());
        return selectPage(confessionalWallPage, lambdaQueryWrapper);
    }
}
